/**   
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-06 09:51:29  
 * Copyright (c) 2015- joysuch-版权所有     
 */

package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.BpRegulationDocumentType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * BpRegulationDocumentTypeDao
 * 
 */
public interface BpRegulationDocumentTypeDao extends JpaRepository<BpRegulationDocumentType, Long> {
    public Page<BpRegulationDocumentType> findAll(Specification<BpRegulationDocumentType> spec, Pageable pageable);

    public List<BpRegulationDocumentType> findAllByDocCodeOrderByNameAsc(String docCode);

    public BpRegulationDocumentType save(BpRegulationDocumentType bean);

    public void delete(BpRegulationDocumentType bean);

    // 查询是否有指定名称的文档类型
    public Integer countByNameAndDocCode(String name, String docCode);

    @Modifying
    @Query("update BpRegulationDocumentType set documentCount=(select count(m) from BpRegulationDocument m where documentTypeId = ?1) where id=?1 ")
    void updateDocumentCount(Long id);

}
